<template>
    <div class="todo_head">
        <input type="text" 
            placeholder="输入任务，并enter确认" 
            v-model="task_cont"
            @keyup.enter="addTask"
        >
    </div>
</template>

<script>
export default {
    name: 'TodoHead',
    data() {
        return {
            task_cont: '',
        }
    },
    props: ['getData'],
    methods: {
        addTask() {
            if(this.task_cont.trim()) {
                let todo = {
                    id: Date.now().toString(),
                    task: this.task_cont,
                    isDone: false,
                }
                this.getData(todo);
            }

            this.task_cont = ''; // 敲完回车，清空输入框里的内容
        }
    }
}
</script>

<style scoped>
.todo_head {
    width: 300px;
    margin: auto;
}

input {
    width: 100%;
    outline: none;
}
</style>